package com.koron.css2.newProjectCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjPubUpFlowInventory;
import com.koron.css2.newProjectCenter.bean.query.PjPubUpFlowInventoryQuery;
import com.koron.css2.newProjectCenter.mapper.PjPubUpFlowInventoryMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;

/**
 * @Author: 苏小龙
 * @CreateTime: 2024-12-04
 * @Description: 工程材料盘点
 * @Version: 1.0
 */
public class PjPubUpFlowInventoryList implements ServerInterface {


    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjPubUpFlowInventoryQuery pubUpInvoiceQuery = JsonUtils.objectToPojo(req.getData(), PjPubUpFlowInventoryQuery.class);
           if(pubUpInvoiceQuery.getHandlerDate()!=null){
                pubUpInvoiceQuery.setHandlerDateFrom(pubUpInvoiceQuery.getHandlerDate()[0]);
                pubUpInvoiceQuery.setHandlerDateTo(pubUpInvoiceQuery.getHandlerDate()[1]);
            }

            PjPubUpFlowInventoryMapper pjPubUpInvoiceMapper= factory.getMapper(PjPubUpFlowInventoryMapper.class);
            PageHelper.startPage(pubUpInvoiceQuery.getPage(), pubUpInvoiceQuery.getPageCount());
            List<PjPubUpFlowInventory> pubUpInvoiceList = pjPubUpInvoiceMapper.getList(pubUpInvoiceQuery);
            Map<String, String> RIM_DJLX = Tools.mapDicByCode(factory, "RIM_DJLX");
            Map<String, String> PDZT_TEST = Tools.mapDicByCode(factory, "PDZT_TEST");
            pubUpInvoiceList.stream().forEach(s->{
                if(null !=s.getReceiptType()){
                    s.setReceiptName(RIM_DJLX.get(s.getReceiptType()));
                }
                if(null!=s.getStatus()){
                    s.setStatusName(PDZT_TEST.get(s.getStatus()));
                }
            });

            MessageBean<PageInfo> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "工程材料盘点查询成功", PageInfo.class);
            messageBean.setData(new PageInfo<>(pubUpInvoiceList));
            return messageBean;
        } catch (Exception e) {
            logger.error("工程材料盘点查询失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "工程材料盘点分页查询失败:", null);
        }
    }
}
